/*
 * VisualClassComponentVia.h
 *
 *  Created on: May 29, 2013
 *      Author: root
 */

#ifndef VISUALCLASSCOMPONENTVIA_H_
#define VISUALCLASSCOMPONENTVIA_H_

#include "gui/VisualComponents/VisualClassesComponent.h"
#include "gui/VisualComponents/VisualComponentVia.h"
#include "../ArrowHead.h"
#include "model/clases/ViaClasses.h"

class VisualClassComponentVia: public VisualComponentVia, public VisualClassesComponent {


public:
	VisualClassComponentVia(VisualComponentConector* start, Diagram* diagram, VisualComponentConector* end = NULL);
	VisualClassComponentVia(const VisualClassComponentVia& other);
	VisualClassComponentVia(Diagram* diagram);
	virtual ~VisualClassComponentVia();

	virtual void load(XmlReader& reader, Diagram* diagram);
	virtual void load(XmlReader& reader, XmlReader& readerModel, Diagram* diagram);
    virtual VisualClassesComponent *getCopy(Diagram* diagram);
	virtual void draw(Cairo::RefPtr<Cairo::Context> ptrContext);
	virtual void showProperties();
	void setTypeOfVia(ViaClasses::TipoDeRelacionEntreClases tipo);

	virtual void store(XmlWriter& writer_rep, XmlWriter& writer_comp, Diagram* diagram) {
		VisualClassesComponent::store(writer_rep, writer_comp, diagram);
		Utils utils;
		if (m_startConector!=NULL) {
			int idStart = diagram->getId(m_startConector->getParent()->getComponent());
			writer_rep.addCurrentNodeProperty("idStart", utils.convertToString(idStart).c_str());
		}
	}
	virtual void update() {
		VisualClassesComponent::update();
	}
	InfluenceArea getInfluenceArea() {
		return VisualComponentVia::getInfluenceArea();
	}

protected:
	virtual void alignPoints(Point *newPoint, Point *alignPoint, int x, int y, bool allignY);

private:
	ArrowHead::ArrowStyle buildArrowSty(ViaClasses::TipoDeRelacionEntreClases type) {
	    		switch (type) {
	    			case ViaClasses::TipoDeRelacionEntreClasesAsociacion:
	    				return ArrowHead::ARROW_LINE;
	    				break;
	    			case ViaClasses::TipoDeRelacionEntreClasesAgregacion:
	    				return ArrowHead::ARROW_DIAMOND;
	    				break;
	    			case ViaClasses::TipoDeRelacionEntreClasesComposicion:
	    				return ArrowHead::ARROW_DIAMOND_FILLED;
	    				break;
	    			case ViaClasses::TipoDeRelacionEntreClasesHerencia:
	    				return ArrowHead::ARROW_SOLID;
	    				break;
	    			case ViaClasses::TipoDeRelacionEntreClasesDependencia:
	    				return ArrowHead::ARROW_OPEN;
	    				break;
	    			default:
	    				return ArrowHead::ARROW_LINE;
	    				break;
	    		}
	    	}
};

#endif /* VISUALCOMPONENTVIADER_H_ */
